package com.walter.quickstart;

import io.quarkus.vertx.http.runtime.filters.Filters;
import io.quarkus.vertx.web.Route;
import io.vertx.ext.web.Router;
import io.vertx.ext.web.RoutingContext;

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;

@ApplicationScoped
public class ApplicationRoutes {

    public void routes(@Observes Router router){
        router.get("/ok").handler(context -> {
            context.response().end("OK from Route");
        });
    }

    @Route(path = "/declare", methods = Route.HttpMethod.GET)
    public void greeting(RoutingContext routingContext){
        String name = routingContext.request().getParam("name");
        if(name == null){
            name = "world";
        }
        routingContext.response().end("OK " + name + " you are right");
    }

    public void filters(@Observes Filters filters){
        filters.register(context -> {
            context.response().putHeader("V-header", "Header added by Vertx Filter");
            context.next();
        },10);
    }
}
